// http://br.spoj.pl/problems/CUBO/
// 1759. O Cubo

#include<iostream>
#include<queue>
#include<vector>
using namespace std;

typedef vector<char> vchar;
typedef vector<vchar> vvchar;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vvbool> vvvbool;
typedef vector<vvvbool> vvvvbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<vvint> vvvint;
typedef vector<vvvint> vvvvint;
typedef pair<int,int> ii;

#define forn(i,n) for(int i=0; i<n; i++)

#define ENRANGO(r,c) (0<=(r) && (r)<rows && 0<=(c) && (c)<cols)
#define POSVALIDA(r,c) (0<=(r) && (r)<rows && 0<=(c) && (c)<cols && M[r][c]=='.')

int dr[4] = {-1,0,1,0};
int dc[4] = {0,1,0,-1};

vvchar M;
vvvvint D;

int pasos(int& sr, int& sc, int dst_r, int dst_c){

	int rows = M.size();
	int cols = M[0].size();
	vvbool V(rows,vbool(cols,false));

	if(!POSVALIDA(dst_r,dst_c)) return -1;
	if( sr==dst_r && sc==dst_c ) return 0;

	if(D[sr][sc][dst_r][dst_c]!=-2) return D[sr][sc][dst_r][dst_c];

	queue<int> q;
	int res = 0;

	q.push(sr);
	q.push(sc);
	q.push(0);

	while(!q.empty() && res==0){

		int r = q.front(); q.pop();
		int c = q.front(); q.pop();
		int m = q.front(); q.pop();

		V[r][c] = true;

		forn(d,4){
			int new_r = r + dr[d];
			int new_c = c + dc[d];
			if( POSVALIDA(new_r,new_c) && !V[new_r][new_c] ){
				if(new_r==dst_r && new_c==dst_c){
					D[sr][sc][dst_r][dst_c] = m+1;
					return m+1;
				}else{
					q.push(new_r);
					q.push(new_c);
					q.push(m+1);
				}
			}
		}
	}
	D[sr][sc][dst_r][dst_c] = -1;
	return -1;
}

ii BFS(const ii& startB, const ii& startS){

	int rows = M.size();
	int cols = M[0].size(); 
	vvvvbool V(rows,vvvbool(cols,vvbool(3,vbool(3,false))));

	queue<int> q;
	q.push(startB.first);
	q.push(startB.second);
	q.push(0);
	q.push(startS.first);
	q.push(startS.second);
	q.push(0);

	while(!q.empty()){

		int br = q.front(); q.pop();
		int bc = q.front(); q.pop();
		int bm = q.front(); q.pop();
		int sr = q.front(); q.pop();
		int sc = q.front(); q.pop();
		int sm = q.front(); q.pop();

		if( abs(br-sr)<2 && abs(bc-sc)<2 )
			V[br][bc][1+br-sr][1+bc-sc] = true;

		forn(d,4){
			int new_br = br + dr[d];		// Potencial pos de B
			int new_bc = bc + dc[d];
			if( ENRANGO(new_br,new_bc) && !V[new_br][new_bc][1+dr[d]][1+dc[d]] ){
				int new_sr = br-dr[d];
				int new_sc = bc-dc[d];

				M[br][bc] = '#';
				int p = pasos(sr,sc,new_sr,new_sc);
				M[br][bc] = '.';

				if(p>=0){
					if(M[new_br][new_bc]=='T'){
						return(ii(bm+1,sm+p+1));
					}else if(M[new_br][new_bc]=='.'){
						q.push(new_br);
						q.push(new_bc);
						q.push(bm+1);
						q.push(br);
						q.push(bc);
						q.push(sm+p+1);
					}
				}
			}
		}
	}

	return(ii(-1,-1));
}

int main(){
	int rows, cols, caso; caso = 1;
	while( cin >> rows && cin >> cols && rows!=0 && cols!=0 ){

		M = vvchar(rows,vchar(cols));
		D = vvvvint(rows,vvvint(cols,vvint(rows,(vint(cols,-2)))));
		ii startS;
		ii startB;

		forn(i,rows) forn(j,cols){
			char c; cin >> c;
			if(c=='S'){
				startS.first = i;
				startS.second = j;
				M[i][j] = '.';
			}else if(c=='B'){
				startB.first = i;
				startB.second = j;
				M[i][j] = '.';
			}else{
				M[i][j] = c;
			}
		}

		ii res = BFS(startB,startS);

		cout << "Instancia " << caso << endl;
		if(res.first==-1&&res.second==-1)
			cout << "Impossivel" << endl << endl;
		else
			cout << res.second << " " << res.first << endl << endl;

		caso++;
	}
	return 0;
}
